<?php
	require_once(dirname(__FILE__) . '/../model/db_driver.php');
    class Forum {
    	private $messages;
		
		public function __construct(){
			$driver = new DbDriver();
			$db_msg = $driver->getForumMessages();
			for($i=0; $i < count($db_msg); $i++){
				$this->messages[$i] = new ForumMessage(
					$db_msg[$i][0],
					$db_msg[$i][1],
					$db_msg[$i][2]
				);
			} //end for
		} //end construct
		
		public function getNumMessages(){
			
			return $this->messages == NULL ? 0 : count($this->messages);
		}
		
		public function getMessage($i){
			return $this->messages[$i];
		}
		
		public function addComment($userId, $text){
		//Inserisce un nuovo commento nella bacheca
			$driver = new DbDriver();
			$driver->addForumMessage($userId, $text);
		}
    } //end clas Forum
	
	class ForumMessage {
		private $data;
		private $userName;
		private $text;
		
		public function __construct($_date, $_userName, $_text){
			$this->data = $_date;
			$this->userName = $_userName;
			$this->text = $_text;
		}
		
		public function getDate(){
			return $this->data;
		}
		
		public function getUser(){
			return $this->userName;
		}
		
		public function getText(){
			return $this->text;
		}
	}
?>